/*
 Typical use of Groovy to drive a Java API call
 This example is a work in progress with respect to long options:
 http://www.nabble.com/How-much-of-CliBuilder-does-work--td16111825.html
 */

 /*
 Copyright 2009 Homosuperiorus LLC 

 Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
 this file except in compliance with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0 

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 implied. See the License for the specific language governing
 permissions and limitations under the License.

 */
 
import org.taglets.pub.tags.*
import org.taglets.exception.*

def cli = new CliBuilder(usage: 'groovy tagGetFollowed.groovy -ep [h]', parser: new org.apache.commons.cli.GnuParser ())
cli.h(longOpt:'help', 'usage information')
cli.e(argName:'email', longOpt:'email', args:1, required: true, 'your username as email address of record at taglets.org')
cli.p(argName:'password', longOpt:'password', args:1, required: true, 'taglets.org password')

def opt = cli.parse(args)
if (!opt) {
	return
}
if( opt.h ) {
	cli.usage
}

String email = opt.e
String password = opt.p

try {
	client = new TagListClient()
	TagListResponse response = client.getList(email, password)
	println "HTTP response code: ${response.getResponseCode()} ${response.getResponseMessage()}"
	println "call succeeded: ${response.succeeded}"
	println "Headers:"
	def headers = response.getHeaderFields()
	headers.each { header -> println "    ${header}" }
} catch (TagletsException e) {
	e.printStackTrace();
}

